package com.guchenbo.study.mvc.servlet31.springmvc.servlet;

import com.guchenbo.study.mvc.servlet31.springmvc.StatusException;
import com.guchenbo.study.mvc.servlet31.springmvc.StudyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author guchenbo
 * @Date 2019/11/30.
 */
@Controller
@ResponseStatus
public class StudyController {
    @Resource
    private StudyService studyService;

    @RequestMapping(value = "/study")
    @ResponseBody
    public String ok(HttpServletResponse response) {
        System.out.println("in study controller");
        studyService.demo();
        return "Spring MVC Servlet 3.0 ok";
    }

    @RequestMapping(value = "/error")
    @ResponseBody
    public String error() throws Exception {
        System.out.println("in study controller error");
        throw new Exception("test error");
    }
    @RequestMapping(value = "/error2")
    @ResponseBody
    public String error2() throws Exception {
        System.out.println("in study controller error");
        throw new StatusException("test error");
    }
}
